import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		userInfo: {
			hasLogin: false,
		},
	},
	mutations: {
		storeLogin(state, payload) {
			const temp = {
				hasLogin: true,
				profile: payload
			}
			state.userInfo = temp
			// 2方式二：持久化存储
			uni.setStorageSync('userInfo', JSON.stringify(temp))
		},
		// 登出
		storeLogout(state) {
			const temp = {
				hasLogin: false,
				profile: ''
			}
			state.userInfo = temp
			uni.removeStorage({
				key: 'userInfo'
			})
		}
	},
	actions: {
		
	}
})

export default store